package com.yanqu.road.dao.impl.activity.suitang;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class CompositeKey {
    private final List<Object> keyParts;

    public CompositeKey(Object ... keyPart) {
        this.keyParts = new ArrayList<>(Arrays.asList(keyPart));
    }

    public CompositeKey(List<Object> keyParts) {
        this.keyParts = keyParts;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CompositeKey that = (CompositeKey) o;
        if (keyParts.size() != that.keyParts.size()) return false;
        for (int i = 0; i < keyParts.size(); i++) {
            if (!Objects.equals(keyParts.get(i), that.keyParts.get(i))) {
                return false;
            }
        }
        return true;
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(keyParts.toArray());
    }
}
